define(['jquery', 'jquery-weui', 'weui'], function ($, JqueryWuei, Weui) {
    var Controller = {
        index: function () {
            $("input,textarea").on("blur", function () {
                setTimeout(function () {
                    window.scrollTo(0, 0);
                }, 100)
            }).on('focus', function () {
                var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
                var offsetTop = $(this).offset().top - (clientHeight / 4);
                setTimeout(function () {
                    window.scrollTo(0, offsetTop);
                }, 100)
            })
            // 初始化判断数据
            if(window.localStorage.book_username==''|| window.localStorage.book_username == undefined || window.localStorage.book_username == null){
                window.localStorage.book_usernum == '';
                $("#js_cell").show();
                $("#js_cell_yes").hide();
                $("#book_button").show();
            }else{
                $.ajax({
                    type: "post",
                    url: "/index.php/index/washing/check",
                    data: { username: window.localStorage.book_username, sid: window.localStorage.book_usernum},
                    success:function(res){
                        if(res.code==1){
                            //alert(res.code);
                            $("#js_cell").hide();
                            $("#js_cell_yes").show();
                            $("#book_button").hide();
                            $("#js_cell_yes_date").html('<p style="font-size:18px">姓名：'+window.localStorage.book_username+'</p><p style="font-size:18px">学号：'+ window.localStorage.book_usernum+'</p><p style="font-size:18px">预约时间：'+res.data.add_time+'<p style="font-size:18px">预约在'+res.data.times+'分钟内有效！</p><p style="font-size:20px;color:red;">请在 '+res.data.in_time+'  前进入</p>');
                        }else{
                            $("#js_cell").show();
                            $("#js_cell_yes").hide();
                            $("#book_button").show();
                        }
                    }
                })
            }            
            // 初始化判断用户 展示信息
            
            $("input[name='yname']").val(window.localStorage.book_username);
            $("input[name='ynum']").val(window.localStorage.book_usernum);


        },
        into:function(){
            $("input,textarea").on("blur", function () {
                setTimeout(function () {
                    window.scrollTo(0, 0);
                }, 100)
            }).on('focus', function () {
                var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
                var offsetTop = $(this).offset().top - (clientHeight / 4);
                setTimeout(function () {
                    window.scrollTo(0, offsetTop);
                }, 100)
            })

            // 初始化判断用户 展示信息
            if (window.localStorage.book_username == '' || window.localStorage.book_username == undefined || window.localStorage.book_username == null) {
                window.localStorage.book_usernum == '';
                $("#js_cell").show();
                $("#book_button").show();

                // setTimeout(function(){
                //     window.location.href="/index.php/index/shower/index";
                // }, 1000); 
                window.location.href="/index.php/index/washing/index";
            } else {
                //alert(window.localStorage.book_username)
                $("input[name='yname']").val(window.localStorage.book_username);
                $("input[name='ynum']").val(window.localStorage.book_usernum);

                setInterval(function () {
                                var date = new Date();//获得当前时间
                                var yy = date.getFullYear();//年份
                                var mm = date.getMonth() + 1;//获得月份
                                mm = (mm < 10 ? "0" + mm : mm);//月份小于10时，前面加个0(例如9 ->09)天，小时，分钟，秒同理
                                var dd = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());//天
                                var hours = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours());//小时
                                var minutes = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes());//分钟
                                var seconds = (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds());//秒
                                document.getElementById("current-time").innerHTML = yy + '年' + mm + "月" + dd + "日 " + hours + ':' + minutes + ':' + seconds;
                                
                                }, 1000);

                
                $.ajax({
                    type: "post",
                    url: "/index.php/index/washing/into",
                    data: { username: window.localStorage.book_username, sid: window.localStorage.book_usernum},
                    success:function(res){
                        if (res.code == 1) {
                            // $.alert(res.msg,function () {
                            //     $("#js_cell").hide();
                            //     $("#js_cell_yes").show();
                            //     $("#js_cell_yes_date").html('<p style="font-size:18px">姓名：'+window.localStorage.book_username+'</p><p style="font-size:18px">学号：'+window.localStorage.book_usernum+'</p><p style="font-size:22px;color:red;">进入浴池成功</p><p style="font-size:18px">当前时间：<p><p id="current-time" style="color:red;font-size:22px;"></p>');
                            //     $("#book_button").hide();
                            // });
                            $("#js_cell").hide();
                            $("#js_cell_yes").show();
                            $("#js_cell_yes_date").html('<p style="font-size:18px">姓名：'+window.localStorage.book_username+'</p><p style="font-size:18px">学号：'+window.localStorage.book_usernum+'</p><p style="font-size:24px;color:red;">进入浴池成功</p><p style="font-size:18px">当前时间：<p><p id="current-time" style="color:red;font-size:24px;"></p>');
                            $("#book_button").hide();                            
                        } else {
                            $.alert({
                                title: res.msg,
                                // text: '提示',
                                onOK: function () {
                                    if(res.code == 0 )
                                    {
                                        window.location.href="/index.php/index/washing/index";
                                    }
                                }
                            });
                        }
                    }
                });



            }
        },
        leave: function () {
            $("input,textarea").on("blur", function () {
                setTimeout(function () {
                    window.scrollTo(0, 0);
                }, 100)
            }).on('focus', function () {
                var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
                var offsetTop = $(this).offset().top - (clientHeight / 4);
                setTimeout(function () {
                    window.scrollTo(0, offsetTop);
                }, 100)
            })

            // 初始化判断用户 展示信息
            if (window.localStorage.book_username == '' || window.localStorage.book_username == undefined || window.localStorage.book_username == null) {
                window.localStorage.book_usernum == '';
                $("#js_cell").show();
                $("#book_button").show();
                
                window.location.href="/index.php/index/washing/index";

            } else {
                $("input[name='yname']").val(window.localStorage.book_username);
                $("input[name='ynum']").val(window.localStorage.book_usernum);

                $.ajax({
                    type: "post",
                    url: "/index.php/index/washing/leave",
                    data: { username: window.localStorage.book_username, sid: window.localStorage.book_usernum},
                    success:function(res){
                        if (res.code == 1) {

                            $("#js_cell").hide();
                            $("#js_cell_yes").show();
                            $("#js_cell_yes_leave").html("<p style='font-size:24px;color:red;'>离开成功<p>");
                            $("#book_button").hide();                
                        } else {
                            $.alert({
                                title: res.msg,
                                onOK: function () {
                                    if(res.code == 0)
                                    {
                                        window.location.href="/index.php/index/washing/index";
                                    }
                                }
                            });
                           
                        }
                    }
                });

            }
        } 
        
    }
    return Controller;
})